<?php
namespace App\Http\Controllers\Item\Fxotary\Front;

use App\Service\Item\Fxotary\Front\DetailService;
use Illuminate\Http\Request;

class DetailController extends BaseController
{
    //项目他们内容

    public function __construct(DetailService $service)
    {
        $this->db = $service;
    }

    //首页
    public function getHomeList(Request $request)
    {
        //header('Access-Control-Allow-Origin: *');
        $res = $this->db->getHomeList();
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //首页2
    public function getHome2List(Request $request)
    {
        //header('Access-Control-Allow-Origin: *');
        $res = $this->db->getHome2List();
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //关于我们
    public function getAbout(Request $request)
    {
        //header('Access-Control-Allow-Origin: *');
        $res = $this->db->getAbout();
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //服务列表
    public function getServiceList(Request $request)
    {
        //header('Access-Control-Allow-Origin: *');
        $res = $this->db->getServiceList();
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //服务详情
    public function getServiceDetail(Request $request)
    {
        //header('Access-Control-Allow-Origin: *');
        $res = $this->db->getServiceDetail();
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //投资列表
    public function getPortfolioList(Request $request)
    {
        //header('Access-Control-Allow-Origin: *');
        $res = $this->db->getPortfolioList();
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //投资网格
    public function getPortfolioGrid(Request $request)
    {
        //header('Access-Control-Allow-Origin: *');
        $res = $this->db->getPortfolioGrid();
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //投资详情
    public function getPortfolioDetail(Request $request)
    {
        //header('Access-Control-Allow-Origin: *');
        $res = $this->db->getPortfolioDetail();
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //团队
    public function getTeam(Request $request)
    {
        //header('Access-Control-Allow-Origin: *');
        $res = $this->db->getTeam();
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //博客网格
    public function getBlogGrid(Request $request)
    {
        //header('Access-Control-Allow-Origin: *');
        $res = $this->db->getBlogGrid();
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //博客列表
    public function getBlogList(Request $request)
    {
        //header('Access-Control-Allow-Origin: *');
        $res = $this->db->getBlogList();
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //博客详情
    public function getBlogDetail(Request $request)
    {
        //header('Access-Control-Allow-Origin: *');
        $res = $this->db->getBlogDetail();
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //联系我们
    public function getContact(Request $request)
    {
        //header('Access-Control-Allow-Origin: *');
        $res = $this->db->getContact();
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //添加用户
    public function addUser(Request $request)
    {
        $pas['nick'] = $request->post('nick', '');
        $pas['phone'] = $request->post('phone', '');
        $pas['email'] = $request->post('email', '');
        $pas['subject'] = $request->post('subject', '');
        $pas['message'] = $request->post('message', '');
        if (!$pas['nick']) {
            return $this->toJson(-2, '用户名必须的');
        };
        if (!$pas['phone']) {
            return $this->toJson(-2, '手机号必须的');
        }
        $res = $this->db->addUser($pas);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }
}